package pers.liyan.shi.computermanager.core;

import lombok.Data;

/**
 * @author ShiLY
 * @version 1.0
 * @date 2020/2/10 23:14
 */
@Data
public class Result<T> {

    public static final Integer OK_CODE = 0;
    public static final Integer FAIL_CODE = -1;

    public static final String OK_CODE_STR = String.valueOf(OK_CODE);
    public static final String FAIL_CODE_STR = String.valueOf(FAIL_CODE);

    private Integer code;
    private String message;
    private T data;

    public static Result ok() {
        Result result = new Result();
        result.setCode(OK_CODE);
        return result;
    }

    public static <T> Result ok(T data) {
        Result<T> result = new Result<>();
        result.setCode(OK_CODE);
        result.setData(data);
        return result;
    }

    public static Result fail(String message) {
        Result result = new Result();
        result.setCode(FAIL_CODE);
        result.setMessage(message);
        return result;
    }
}
